home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
madtrb9.arc
/
HEAPTEST.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-12-11
|
3KB
|
82 lines
program HeapTest (input, output) ;
{ This program demonstrates a bug in Turbo's version 2. Put
10 integers on the stack, then release the stack and put
10 integers on the stack again. In version 1.0, you will
get the same results - as it should be. In version 2.0,
you will get different answers. Apparently, the procedure
Release(HeapTop) in not working properly. The procedure
ReleaseHeap is a replacement for Release (HeapTop) and seems
to work correctly. }
type
IntegerPointer = ^integer ;
var
Number : ^integer ;
HeapTop : ^integer ;
Mem : real ;
Procedure ReleaseHeap (AHeapPointer : IntegerPointer) ;
var
i : integer ;
begin
i := ((seg(heapptr^) - seg(AHeapPointer^)) shl 4) +
(ofs(heapptr^) - ofs(AHeapPointer^)) ;
FreeMem(AHeapPointer, i) ;
end ;
procedure report ; { report memory available }
begin
Mem := memAvail ;
if (Mem < 0) then Mem := 65536.0 + MemAvail ;
write ('MemAvail = ', Mem :7:0, ' paragraphs ', Mem * 16.0 :9:0, ' bytes') ;
end ;
procedure FillTheHeap(xc,yc, Depth : integer) ; { fill the heap to depth }
var
n : integer ;
begin
for n := 1 to Depth do
begin
New(Number) ;
Number^ := n ;
gotoxy(xc,yc) ;
report ;
end ;
end ;
begin { main }
clrscr;
writeln(' This program demonstrates a bug in Turbo version 2. Put');
writeln(' 10 integers on the stack, then release the stack and put ');
writeln(' 10 integers on the stack again. In version 1.0, you will');
writeln(' get the same results - as it should be. In version 2.0, ');
writeln(' you will get different answers. Apparently, the procedure');
writeln(' Release(HeapTop) in not working properly. The procedure ');
writeln(' ReleaseHeap is a replacement for Release (HeapTop) and seems');
writeln(' to work correctly. Try your version by replacing the call to');
writeln(' ReleaseHeap with Release. Turbo version 3.x works with both.');
writeln(' The heap operations have functioned properly when the memavail');
writeln(' in the third and fourth lines are equal to the first and second');
writeln(' lines respectively.');
writeln;
writeln;
Mark(HeapTop) ; { mark the top of the heap }
gotoxy(5,20) ;
write('1: ');
report ; { 1: report memory available }
write('2: ');
FillTheHeap(5,21,10) ; { 2: fill the heap with 10 integers }
{*********************** Change these two calls **********************}
ReleaseHeap(HeapTop) ; { release the heap using the fix }
{ release (HeapTop) ;} { This does not work! }
{*********************** to test you turbo version *******************}
gotoxy(5,22) ;
write('3: ');
report ; { 3: report memory available; should be same as 1 }
write('4: ');
FillTheHeap(5,23,10) ; { 4: put 10 integers on again; should be same as 2 }
end.